package cn.jari.erp.inventory.controllers.base;

import cn.jari.erp.Roles;
import cn.jari.erp.inventory.api.InventoryCategoryService;
import cn.jari.erp.inventory.dto.InventoryCategoryReference;
import cn.jari.erp.inventory.dto.UpdateInventoryCategoryCommand;
import cn.jari.erp.inventory.dto.DeleteInventoryCategoryCommand;
import cn.jari.erp.inventory.dto.InventoryCategoryDto;
import cn.jari.erp.inventory.dto.CreateInventoryCategoryCommand;
import javax.validation.constraints.NotNull;
import com.csicit.ace.api.annotations.OkMessage;
import com.csicit.ace.utils.ApplicationContextUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
 * 警告：代码由鲲舟平台生成，请勿手动修改。
 * Warn: This class file is generated by JARI-ACE platform, please do not modify manually。
 */

/**
 * InventoryCategory控制器基类
 */
@RequiredArgsConstructor
public abstract class AbstractInventoryCategoryController {
    private InventoryCategoryService inventoryCategoryService() {
        return ApplicationContextUtil.getBean(InventoryCategoryService.class);
    }
    /**
     * 根据名称获取
     *
     * @param name 名称
     * @return {@link InventoryCategoryReference}
     */
    @Operation(summary = "根据名称获取")
    @GetMapping(path = "/{name}")
    InventoryCategoryReference getByName(
        @PathVariable
        @Parameter(description = "名称")
        @NotNull(message = "{error.common.isNull}")
        String name
    ) {
        return doGetByName(name);
    }

    protected InventoryCategoryReference doGetByName(String name){
        return inventoryCategoryService().getByName(name);
    }

    /**
     * 创建存货类别
     *
     * @param command 创建命令参数{@link CreateInventoryCategoryCommand}
     * @return {@link InventoryCategoryDto}
     */
    @Operation(summary = "创建存货类别")
    @PostMapping(path = "")
    @PreAuthorize("hasRole('" + Roles.INVENTORY_MANAGE + "')")
    InventoryCategoryDto createInventoryCategory(
        @RequestBody
        @Validated
        @Parameter(description = "创建命令参数")
        @NotNull(message = "{error.common.isNull}")
        CreateInventoryCategoryCommand command
    ) {
        return doCreateInventoryCategory(command);
    }

    protected InventoryCategoryDto doCreateInventoryCategory(CreateInventoryCategoryCommand command){
        return inventoryCategoryService().createInventoryCategory(command);
    }
    /**
     * 修改存货类别
     *
     * @param command 修改命令参数{@link UpdateInventoryCategoryCommand}
     * @return {@link InventoryCategoryDto}
     */
    @Operation(summary = "修改存货类别")
    @PutMapping(path = "")
    @PreAuthorize("hasRole('" + Roles.INVENTORY_MANAGE + "')")
    InventoryCategoryDto updateInventoryCategory(
        @RequestBody
        @Validated
        @Parameter(description = "修改命令参数")
        @NotNull(message = "{error.common.isNull}")
        UpdateInventoryCategoryCommand command
    ) {
        return doUpdateInventoryCategory(command);
    }

    protected InventoryCategoryDto doUpdateInventoryCategory(UpdateInventoryCategoryCommand command){
        return inventoryCategoryService().updateInventoryCategory(command);
    }
    /**
     * 创建存货类别
     *
     * @param command 创建命令参数{@link DeleteInventoryCategoryCommand}
     * @return {@link InventoryCategoryDto}
     */
    @Operation(summary = "创建存货类别")
    @PostMapping(path = "/delete")
    @PreAuthorize("hasRole('" + Roles.INVENTORY_MANAGE + "')")
    InventoryCategoryDto deleteInventoryCategory(
        @RequestBody
        @Validated
        @Parameter(description = "创建命令参数")
        @NotNull(message = "{error.common.isNull}")
        DeleteInventoryCategoryCommand command
    ) {
        return doDeleteInventoryCategory(command);
    }

    protected InventoryCategoryDto doDeleteInventoryCategory(DeleteInventoryCategoryCommand command){
        return inventoryCategoryService().deleteInventoryCategory(command);
    }
}
